package com.ccx.coachsite.task;

import org.json.JSONObject;

import android.content.Context;

import com.ccx.coachsite.bus.Account;
import com.ccx.coachsite.bus.AccountMgr;
import com.ccx.coachsite.http.HttpCallBack;
import com.ccx.coachsite.http.HttpRequest;
import com.ccx.coachsite.http.UrlConfig;
import com.ccx.coachsite.util.Log;

public class ExpertInfoTask extends TaskBase 
{	
	private Account account;
	
	public ExpertInfoTask(HttpCallBack<?> iCall, Context context, Account account) {
		super(iCall, context);
		mTaskType = TaskType.TaskTypeExpertInfo;
		this.account = account;
	}

	@Override
	protected String genUrl(HttpRequest request) {
		String url = String.format(
				UrlConfig.getUrlByKey(UrlConfig.GetMyExpertUrlKey),
				mMobile).trim();
		return url;
	}

	@Override
	protected void onDataParse(String responseString) 
	{
		try {
			JSONObject jsonObject = new JSONObject(responseString);
			JSONObject respsonObject = jsonObject.getJSONObject("response");
			account.setExpertName(respsonObject.getString("nickName"));
			account.setExpertIcon(respsonObject.getString("icon"));
			account.setExpertPhone(respsonObject.getString("phone"));
			account.setHasExpert(false);
			if(!respsonObject.isNull("id"))
			{
				account.setHasExpert(true);
				account.setExpertId(respsonObject.getInt("id"));
			}

			if(!respsonObject.isNull("userId"))
			{
				account.setHasExpert(true);
				account.setExpertId(respsonObject.getInt("userId"));
			}
			//account.setExpertId(respsonObject.getInt("id"));
			AccountMgr.saveAccountInfo(mContext, account);
		} catch (Exception e) {
			Log.e(e.getMessage(), e);
		} finally {
		}
	} 

}